package com.bbc.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.bbc.MainActivity;
import com.bbc.R;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by ${cbf} on 2017/10/13.
 */

public class StartActivity extends AppCompatActivity {

    private TextView mTvTime;
    private Timer mTask = new Timer();
    private int recLen = 10;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start_time_activity);
        mTvTime = (TextView) findViewById(R.id.tv_time);
        mTask.schedule(msk, 1000, 1000);
    }

    TimerTask msk = new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    recLen--;
                    mTvTime.setText(recLen+"秒");
                    if (recLen<=0){
                        mTask.cancel();
                        startActivity(new Intent(StartActivity.this, MainActivity.class));
                        finish();
                    }
                }
            });
        }
    };
}
